import request from '@/utils/request';

// 查询列表
export function getList(data) {
  return request({
    url: '/account/user/getlist',
    method: 'post',
    data: data,
  });
}

// 查询详细
export function getItem(id) {
  return request({
    url: '/account/user/getbyid',
    method: 'get',
    params: { id: id },
  });
}

// 新增
export function add(data) {
  return request({
    url: '/account/user/add',
    method: 'post',
    data: data,
  });
}

// 修改
export function update(data) {
  return request({
    url: '/account/user/update',
    method: 'post',
    data: data,
  });
}

// 删除
export function del(id) {
  return request({
    url: '/account/user/delbyid',
    method: 'get',
    params: { id: id },
  });
}

// 查询日志
export function getLogs(data) {
  return request({
    url: '/account/user/getlogs',
    method: 'post',
    data: data,
  });
}

// 用户状态修改
export function changeUserStatus(id, state) {
  const data = {
    id,
    state,
  };
  return request({
    url: '/account/user/setstate',
    method: 'get',
    params: data,
  });
}


// 用户密码重置
export function resetUserPwd(userId, password) {
  const data = {
    userId,
    password,
  };
  return request({
    url: '/system/user/resetPwd',
    method: 'put',
    data: data,
  });
}


// 查询用户个人信息
export function getUserProfile() {
  return request({
    url: '/system/user/profile',
    method: 'get',
  });
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: '/system/user/profile',
    method: 'put',
    data: data,
  });
}

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword,
  };
  return request({
    url: '/system/user/profile/updatePwd',
    method: 'put',
    params: data,
  });
}

// 用户头像上传
export function uploadAvatar(data) {
  return request({
    url: '/auth/avatar',
    method: 'post',
    data: data,
  });
}

// 下载用户导入模板
export function importTemplate() {
  return request({
    url: '/system/user/importTemplate',
    method: 'get',
  });
}

// 查询授权角色
export function getAuthRole(userId) {
  return request({
    url: '/system/user/authRole/' + userId,
    method: 'get',
  });
}

// 保存授权角色
export function updateAuthRole(data) {
  return request({
    url: '/system/user/authRole',
    method: 'put',
    params: data,
  });
}


// 保存授权角色
export function updatePassWord({ confirmpass, newpass, oldpass }) {
  return request({
    url: '/account/user/updatepassword',
    method: 'get',
    params: {confirmpass, newpass, oldpass},
  });
}
